﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;

namespace WebsiteAdmin.Wilson.ProInfo
{
    public partial class ProOtherImgList : System.Web.UI.Page
    {
        public int proId = 0;
        public string proName = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                proId = Convert.ToInt16(Request["proId"], CultureInfo.InvariantCulture);
                ProInfo(Global.ConnWilson, proId);
                BindOtherImgList(Global.ConnWilson, proId);
            }
        }

        protected void ProInfo(string strCon,int proId) 
        {
            using (DataTable dt = Bll.Product.Single(strCon, proId)) 
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    proName = dt.Rows[0]["ProName"].ToString();
                }
            }
        }

        protected void BindOtherImgList(string strCon,int proId) 
        {
            using (DataTable dt = Bll.ProOtherInfo.MULTIPLE(strCon, proId))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    this.repOtherImgList.DataSource = dt.DefaultView;
                    this.repOtherImgList.DataBind();
                }
            }
        }

        protected void repOtherImgList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView rowv = (DataRowView)e.Item.DataItem;
                BindImg("imgBig", "OtherBigImgURL", rowv, e);
                BindImg("imgMedium", "OtherMediumImgURL", rowv, e);
                BindImg("imgSmall", "OtherSmallImgURL", rowv, e);
            }
        }
        
        protected void BindImg(string controlId,string columnName,DataRowView rowv,RepeaterItemEventArgs e) 
        {
            Image img = (Image)e.Item.FindControl(controlId);
            if (rowv[columnName].ToString().Trim().Length > 0)
            {
                img.ImageUrl = rowv[columnName].ToString();
            }
            else
            {
                img.ImageUrl = "/Images/view.png";
            }
        }
    }
}
